package Server.Model.Hall;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import Server.Agent.GameAgent;
import Server.Agent.GameConfig;
import Server.Model.Base.SHMUser;
import Server.Model.Base.UserGoldChange;
import Server.Model.Base.UserRmbChange;
import Server.Model.Base.UserShareInfo;
import admin.AdminRedis;
import club.ClubMgr;
import club.ClubRedis;
import common.routine.CommonDef;
import common.routine.JsonUtils;
import common.routine.MailSender;
import common.routine.RedisUtil;
import net.sf.json.JSONObject;
import rank.DwcRankDef;
import redis.clients.jedis.Jedis;
import redis.protocal.DbInfoMgr;
import redis.protocal.DwcRedisRecord;
import redis.protocal.UserRedisInfo;
import robot.GoldMgr;

public class DwcGameMgr {
	public final String DB_DWC_AUTOCLUB_WANFA_MAP = "DB_DWC_AUTPCLUB_NAME_MAP";
	public final String DB_DWC_AUTOCLUB_NAMEID_MAP = "DB_DWC_AUTOCLUB_NAMEID_MAP";
	private Map<String,String> m_mapData = new HashMap<String,String>();
	private static DwcGameMgr _instance = null;
	public static DwcGameMgr getInstance(){
		if(_instance == null){
			_instance = new DwcGameMgr();
			_instance.init();
		}
		return _instance;
	}
	public void init(){
		startRankThread();
	}
	public void startRankThread(){
		
	}
	public void getZjhUserNum(JSONObject json){
		if(!m_mapData.containsKey("zjhUser")){
			//需要统计用户数据
			m_mapData.put("zjh1","" + (int)(Math.random() * 2000));
			m_mapData.put("zjh2","" + (int)(Math.random() * 1000));
			m_mapData.put("zjh3","" + (int)(Math.random() * 500));
			m_mapData.put("zjh4","" + (int)(Math.random() * 200));
			m_mapData.put("zjhUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("zjh" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getHzmjUserNum(JSONObject json){
		if(!m_mapData.containsKey("hzmjUser")){
			//需要统计用户数据
			m_mapData.put("hzmj1","" + (int)(Math.random() * 2000));
			m_mapData.put("hzmj2","" + (int)(Math.random() * 1000));
			m_mapData.put("hzmj3","" + (int)(Math.random() * 500));
			m_mapData.put("hzmj4","" + (int)(Math.random() * 200));
			m_mapData.put("hzmjUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("hzmj" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getNNUserNum(JSONObject json){
		if(!m_mapData.containsKey("NNUser")){
			//需要统计用户数据
			m_mapData.put("niuniu1","" + (int)(Math.random() * 2000));
			m_mapData.put("niuniu2","" + (int)(Math.random() * 1000));
			m_mapData.put("niuniu3","" + (int)(Math.random() * 500));
			m_mapData.put("niuniu4","" + (int)(Math.random() * 200));
			m_mapData.put("NNUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("niuniu" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getPdkUserNum(JSONObject json){
		if(!m_mapData.containsKey("PDKUser")){
			//需要统计用户数据
			m_mapData.put("pdk1","" + (int)(Math.random() * 2000));
			m_mapData.put("pdk2","" + (int)(Math.random() * 1000));
			m_mapData.put("pdk3","" + (int)(Math.random() * 500));
			m_mapData.put("pdk4","" + (int)(Math.random() * 200));
			m_mapData.put("PDKUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("pdk" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getDdzUserNum(JSONObject json){
		if(!m_mapData.containsKey("DDZUser")){
			//需要统计用户数据
			m_mapData.put("ddz1","" + (int)(Math.random() * 2000));
			m_mapData.put("ddz2","" + (int)(Math.random() * 1000));
			m_mapData.put("ddz3","" + (int)(Math.random() * 500));
			m_mapData.put("ddz4","" + (int)(Math.random() * 200));
			m_mapData.put("DDZUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("ddz" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getTtzUserNum(JSONObject json){
		if(!m_mapData.containsKey("TTZUser")){
			//需要统计用户数据
			m_mapData.put("ttz1","" + (int)(Math.random() * 2000));
			m_mapData.put("ttz2","" + (int)(Math.random() * 1000));
			m_mapData.put("ttz3","" + (int)(Math.random() * 500));
			m_mapData.put("ttz4","" + (int)(Math.random() * 200));
			m_mapData.put("TTZUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("ttz" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getSszUserNum(JSONObject json){
		if(!m_mapData.containsKey("SSZUser")){
			//需要统计用户数据
			m_mapData.put("ssz1","" + (int)(Math.random() * 2000));
			m_mapData.put("ssz2","" + (int)(Math.random() * 1000));
			m_mapData.put("ssz3","" + (int)(Math.random() * 500));
			m_mapData.put("ssz4","" + (int)(Math.random() * 200));
			m_mapData.put("SSZUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("ssz" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getBiJiUserNum(JSONObject json){
		if(!m_mapData.containsKey("BJUser")){
			//需要统计用户数据
			m_mapData.put("bj1","" + (int)(Math.random() * 2000));
			m_mapData.put("bj2","" + (int)(Math.random() * 1000));
			m_mapData.put("bj3","" + (int)(Math.random() * 500));
			m_mapData.put("bj4","" + (int)(Math.random() * 200));
			m_mapData.put("BJUser","" + 1);
		}
		for(int i = 1;i < 5;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("bj" + i)));
			int num = json.optInt("" + i);
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getSgjUserNum(JSONObject json){
		if(!m_mapData.containsKey("SGJUser")){
			//需要统计用户数据
			m_mapData.put("sgj1","" + (int)(Math.random() * 1000));
			m_mapData.put("sgj2","" + (int)(Math.random() * 500));
			m_mapData.put("sgj3","" + (int)(Math.random() * 200));
			m_mapData.put("SGJUser","" + 1);
		}
		for(int i = 1;i < 4;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("sgj" + i)));
			int num = json.optInt("" + i);
			if(num == 0){
				continue;
			}
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getBRSgjUserNum(JSONObject json){
		if(!m_mapData.containsKey("BRSGJUser")){
			//需要统计用户数据
			m_mapData.put("brsgj1","" + (int)(Math.random() * 1000));
			m_mapData.put("brsgj2","" + (int)(Math.random() * 500));
			m_mapData.put("brsgj3","" + (int)(Math.random() * 200));
			m_mapData.put("BRSGJUser","" + 1);
		}
		for(int i = 1;i < 4;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("brsgj" + i)));
			int num = json.optInt("" + i);
			if(num == 0){
				continue;
			}
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	public void getFKFishUserNum(JSONObject json){
		if(!m_mapData.containsKey("FKFISHUser")){
			//需要统计用户数据
			m_mapData.put("fkfish1","" + (int)(Math.random() * 1000));
			m_mapData.put("fkfish2","" + (int)(Math.random() * 500));
			m_mapData.put("fkfish3","" + (int)(Math.random() * 200));
			m_mapData.put("FKFISHUser","" + 1);
		}
		for(int i = 1;i < 4;i++){
			json.put("" + i,Integer.parseInt(m_mapData.get("fkfish" + i)));
			int num = json.optInt("" + i);
			if(num == 0){
				continue;
			}
			num += num / 4 - CommonDef.getRandomInt(num / 2);
			json.put("" + i, "" + num);
		}
	}
	boolean HandleOn_DwcRequest(GameAgent agent, JSONObject root){
		switch(root.optString("subcmd")){
			case "dwc_user_vipcharge":{
				//发邮件
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject json = new JSONObject();
				json.put("uid", uid);
				json.put("昵称", shmUser.getNickName(null));
				json.put("姓名", root.optString("name"));
				json.put("支付方式", root.optString("type"));
				json.put("人民币", root.optDouble("rmb"));
				json.put("附加信息", root.optString("add"));
				MailSender.sendDwcVipCharge("VIP充值", json.toString());
				
				//加入redis数据库

				json.put("time", UserRedisInfo.getRecordTimeKey());
				json.put("status", 0);
				DwcRedisRecord.getInstance().addVipChargeInfo(json.toString());
				break;
			}
			case "dwc_user_del_msg":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String title = root.optString("title");
				String time = root.optString("localtime");
				DwcRedisRecord.getInstance().removeUserMsg(uid,title,time);
				break;
			}
			case "dwc_user_jyfk":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String title = "意见反馈" + root.optString("title");
				String content = root.optString("content");
				String userName = shmUser.getNickName(null);
				JSONObject json = new JSONObject();
				json.put("from",userName);
				json.put("uid", uid);
				json.put("title", title);
				json.put("title", title);
				json.put("content", content);
				json.put("status", 0);
				json.put("time", UserRedisInfo.getRecordTimeKey());
				DwcRedisRecord.getInstance().addSysMail(json);
				//发邮件
				MailSender.sendDwcJYFK(title, json.toString());
				//返回
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_user_jyfk");
				rev.put("success", 1);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_user_swhz":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String title = "商务合作" + root.optString("title");
				String content = root.optString("content");
				String userName = shmUser.getNickName(null);
				int time = (int) System.currentTimeMillis();
				JSONObject json = new JSONObject();
				json.put("from",userName);
				json.put("uid", uid);
				json.put("title", title);
				json.put("title", title);
				json.put("content", content);
				json.put("status", 0);
				json.put("time", UserRedisInfo.getRecordTimeKey());
				DwcRedisRecord.getInstance().addSysMail(json);
				//发邮件
				MailSender.sendDwcJYFK(title, json.toString());
				//返回
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_user_swhz");
				rev.put("success", 1);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_has_user_msg":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int time = root.optInt("localtime");
				boolean has = DwcRedisRecord.getInstance().hasUserMsgUpdate(uid,time);
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_has_user_msg");
				rev.put("has", has ?1:0);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_user_msg":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int time = root.optInt("localtime");
				List<String> mails = DwcRedisRecord.getInstance().getUserMsgList(uid,time);
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_user_msg");
				rev.put("data", mails);
				rev.put("time",(int)(System.currentTimeMillis() / 1000));
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_set_headurl":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int index = root.optInt("index");
				if(index >= 1 && index <= 8){
					String headurl = GameConfig.getInstance().get("APP_HOST");
					if(!headurl.startsWith("http")){
						headurl = "http://" + headurl;
					}
					headurl += "/app/headimg/head";
					headurl += index;
					headurl += ".png";
					UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
					info.json.put("headurl",headurl);
					DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
					DbInfoMgr.getInstance().setUserAvatarUrl(uid, headurl);
					dthall.getInstance().m_mapAvatar.put(uid, headurl);
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_set_headurl");
					rev.put("success", 1);
					agent.SendMessage(rev.toString());
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_set_headurl");
					rev.put("success", 0);
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_broadcast":{
				//发布消息队列
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String text = root.optString("text");
				net.sf.json.JSONObject pub = new net.sf.json.JSONObject();
				pub.put("command","public_dwc_broadcast");
				pub.put("value1",shmUser.getNickName(null) + "说: " +  text);
				AdminRedis.getInstance().pubAdminSubMsg(pub);
				break;
			}
			case "dwc_chongzhi_test":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				double value = root.optDouble("value");
				info.addUserRmb1_1(value);
				DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid,info.getUserInfoStr());
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_chongzhi_test");
				rev.put("success", 1);
				rev.put("gold", info.getUserRmb1_1());
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_duihuan_bindinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				JSONObject rev = new JSONObject();
				rev.put("command","dwc_duihuan_bindinfo");
				rev.put("zfb_account", info.json.optString("bind_zfb_account"));
				rev.put("zfb_name", info.json.optString("bind_zfb_name"));
				rev.put("yh_account",info.json.optString("bind_yh_account"));
				rev.put("yh_name", info.json.optString("bind_yh_name"));
				rev.put("yh_mingzi", info.json.optString("bind_yh_mingzi"));
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_duihuan_bind":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				String type = root.optString("type");
				String account = root.optString("account");
				if(type.equals("zfbinfo")){
					info.json.put("bind_zfb_account", account);
					info.json.put("bind_zfb_name", root.optString("name"));
					//发邮件通知客服提现拿到银行信息
					MailSender.sendUserBindYinHang(root.toString());
				}else if(type.equals("yinhanginfo")){
//		            zhihang:data.zhihang,
//		            sheng:data.sheng,
//		            city:data.city
					info.json.put("bind_yh_account", account);
					info.json.put("bind_yh_name", root.optString("name"));
					info.json.put("bind_yh_mingzi", root.optString("mingzi"));
					info.json.put("bind_yh_zhihang", root.optString("zhihang"));
					info.json.put("bind_yh_sheng", root.optString("sheng"));
					info.json.put("bind_yh_city", root.optString("city"));
					//发邮件通知客服提现拿到银行信息
					MailSender.sendUserBindYinHang(root.toString());
				}
				DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_duihuan_bind");
				rev.put("success", 1);
				rev.put("type", type);
				rev.put("account", account);
				rev.put("name", root.optString("name"));
				if(type.equals("yinhanginfo")){
					rev.put("name", root.optString("name"));
					rev.put("yinhang", root.optString("mingzi"));
				}
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_duihuan_op":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_duihuan_op");
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				if(info.json.optInt("isTxing") == 1){
					//用户存在没有完成的订单
					rev.put("success", 0);
					rev.put("reason", "您存在未完成的提现订单，请等完成之后继续提现,或者联系客服处理");
					agent.SendMessage(rev.toString());
					return false;
				}
				double value = root.optDouble("gold");
				String type = root.optString("type");
				if(info.getUserRmb1_1() > value){
					//可以提现,看下是否是自动提现，自动则开始调用，非自动则记录交给客服处理
//					info.json.put("bind_zfb_account", account);
//					info.json.put("bind_zfb_name", root.optString("name"));
//					info.json.put("bind_yh_account", account);
//					info.json.put("bind_yh_name", root.optString("name"));
//					info.json.put("bind_yh_mingzi", root.optString("yinhang"));
//					info.json.put("bind_yh_zhihang", root.optString("zhihang"));
//					info.json.put("bind_yh_sheng", root.optString("sheng"));
//					info.json.put("bind_yh_city", root.optString("city"));
					if(type.equals("zfb")){
						//使用支付宝
						String name = info.json.optString("bind_zfb_name");
						String account = info.json.optString("bind_zfb_account");
						if(name.isEmpty() || account.isEmpty()){
							rev.put("success", 0);
							rev.put("reason", "没有发现绑定的支付包帐号,请联系客服处理");
							agent.SendMessage(rev.toString());
							return false;
						}
						//加入redis
						DwcRedisRecord.getInstance().addUserTxApply(uid,shmUser.getNickName(null),value,"支付宝",name,account,root.toString());
					}else if(type.equals("yinhang")){
						//使用银行卡
						String name = info.json.optString("bind_yh_name");
						String account = info.json.optString("bind_yh_account");
						String yinhang = info.json.optString("bind_yh_mingzi");
						String zhiHang = info.json.optString("bind_yh_zhihang");
						String sheng = info.json.optString("bind_yh_sheng");
						String city = info.json.optString("bind_yh_city");
						if(name.isEmpty() || account.isEmpty() ||yinhang.isEmpty()){
							rev.put("success", 0);
							rev.put("reason", "没有发现绑定的银行帐号,请联系客服处理");
							agent.SendMessage(rev.toString());
							return false;
						}
						//加入redis
						DwcRedisRecord.getInstance().addUserTxApply(uid,shmUser.getNickName(null),value,"银行",name,account,yinhang + "_" + zhiHang +"_" + sheng + "_" + city);
					}else{
						
					}
					info.addUserRmb1_1(-value);
					info.json.put("isTxing", 1);
					rev.put("left", info.getUserRmb1_1());
					DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
					rev.put("success", 1);
					rev.put("reason","兑换成功,请过一会检查您的相应账户,如有疑问,请发信息给客服");
					agent.SendMessage(rev.toString());
					//发起邮件通知
					MailSender.sendUserApplyTx(uid,shmUser.getNickName(null),root.toString() );
				}else{
					rev.put("success", 0);
					rev.put("reason", "账户没有那么多金额，请检查...");
				}
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_enter_safebox":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				String passwd = root.optString("passwd");
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_enter_safebox");
				if(!info.isSafeBoxPasswordOk(passwd)){
					rev.put("success", 0);
				}else{
					rev.put("success", 1);
					rev.put("rmbinbox", info.getBundFromSafeBox());
					rev.put("rmbinaccount", info.getUserRmb1_1());
					rev.put("goldinbox", info.getGoldFromSafeBox());
					rev.put("goldinaccount",shmUser.getCoin(0));
				}
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_op_safebox":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				if(root.optString("type").equals("RMB")){
					double inbox = root.optDouble("inbox");
					double inaccount = root.optDouble("inaccount");
					double hasinbox = info.getBundFromSafeBox();
					double hasinaccount = info.getUserRmb1_1();
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_op_safebox");
					double has = inbox + inaccount;
					double now = hasinbox + hasinaccount;
					BigDecimal b1 = new BigDecimal(has);
					has = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
					BigDecimal b2 = new BigDecimal(now);
					now = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 
					if(has == now){
						rev.put("success", 1);
						info.saveBundIntoSafeBox(inbox);
						info.setUserRmb1_1(inaccount);
						rev.put("inbox", inbox);
						rev.put("inaccount", inaccount);
					}else{
						rev.put("success",0);
					}
					agent.SendMessage(rev.toString());
					DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
				}else{
					int inbox = root.optInt("inbox");
					int inaccount = root.optInt("inaccount");
					int hasinbox = info.getGoldFromSafeBox();
					int hasinaccount = shmUser.getCoin(0);
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_op_safebox");
					if(inbox + inaccount == hasinbox + hasinaccount){
						rev.put("success", 1);
						info.saveGoldIntoSafeBox(inbox);
						shmUser.getCoin(inaccount - shmUser.getCoin(0));
						rev.put("inbox", inbox);
						rev.put("inaccount", inaccount);
					}else{
						rev.put("success", 0);
					}
					agent.SendMessage(rev.toString());
					DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
				}
				break;
			}
			case "dwc_changepass_safebox":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				UserRedisInfo info = dthall.getInstance().getSafeUserRedisInfo(uid);
				String newpass = root.optString("newpass");
				info.setSafeBoxPassword(newpass);
				DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, info.getUserInfoStr());
				JSONObject json = new JSONObject();
				json.put("command", "dwc_changepass_safebox");
				json.put("success", 1);
				agent.SendMessage(json.toString());
				break;
			}
			case "dwc_usernum_inzjh":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getZjhUserNum(rev);
				rev.put("command","dwc_usernum_inzjh");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inhzmj":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getHzmjUserNum(rev);
				rev.put("command","dwc_usernum_inhzmj");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_innn":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getNNUserNum(rev);
				rev.put("command","dwc_usernum_innn");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inpdk":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getPdkUserNum(rev);
				rev.put("command","dwc_usernum_inpdk");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inddz":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getDdzUserNum(rev);
				rev.put("command","dwc_usernum_inddz");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inttz":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getTtzUserNum(rev);
				rev.put("command","dwc_usernum_inttz");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inssz":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getSszUserNum(rev);
				rev.put("command","dwc_usernum_inssz");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inbiji":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getBiJiUserNum(rev);
				rev.put("command","dwc_usernum_inbiji");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_insgj":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getSgjUserNum(rev);
				rev.put("command","dwc_usernum_insgj");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_inbrsgj":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getBRSgjUserNum(rev);
				rev.put("command","dwc_usernum_inbrsgj");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_usernum_infkfish":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				DwcGameMgr mgr = DwcGameMgr.getInstance();
				mgr.getFKFishUserNum(rev);
				rev.put("command","dwc_usernum_infkfish");
		
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_enter_game":{
				//这里逻辑，跟局客户端的信息创建俱乐部，实际上这个所有的玩家均在一个俱乐部
				//这里相当于用户在俱乐部内点击了快速加入
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String gametype = root.optString("type");
				String name = root.optString("name");
				String difen = root.optString("difen");
				String limit = root.optString("limit");
				String key = name + "_" + gametype + "_" + difen + "_" + limit;
				String cnName = root.optString("cnName");
				String param = root.optString("param");
				String desc = root.optString("desc");
				String maxnum = root.optString("maxnum");
				String jushu = root.optString("jushu");
				Jedis jedis = RedisUtil.getJedis();
				String clubiddata = jedis.hget(DB_DWC_AUTOCLUB_NAMEID_MAP, key);
				int clubid = 0;
				if(clubiddata == null){
					//次俱乐部不存在，那就创建一个吧
					clubid = ClubMgr.getInstance().getHandler().createDwcAutoClub(key);
					if(clubid == 0){
						JSONObject json = new JSONObject();
						json.put("command", "dwc_enter_game");
						json.put("success", 0);
						json.put("reason","找不到对应的房间，请选择别的玩法进入...");
						agent.SendMessage(json.toString());
						return true;
					}
					jedis.hset(DB_DWC_AUTOCLUB_NAMEID_MAP,key,"" +  clubid);
					//添加玩法
					ClubMgr.getInstance().getHandler().addDwcAutoClubWanFa(clubid, desc, cnName, param, name, Double.parseDouble(difen),
							Integer.parseInt(limit), Integer.parseInt(limit), Integer.parseInt(maxnum), Integer.parseInt(jushu));
				}else{
					clubid = Integer.parseInt(jedis.hget(DB_DWC_AUTOCLUB_NAMEID_MAP, key));
				}
				RedisUtil.returnResource(jedis);
				//现在直接加入此俱乐部的玩法，系统自动进入
				ClubRedis redis = ClubRedis.getInstance();
				Map<String,String> alls = redis.getAllClubWanFa(clubid);
				//找到最大的玩法id
				int wanfaId = -1;
				for(String value : alls.keySet()){
					int id = Integer.parseInt(value);
					if(id >= wanfaId)
						wanfaId = id;
				}
				JSONObject info = new JSONObject();
				String data = "JoinWanFa|";
				data += clubid;
				data += "|" + wanfaId;
				info.put("data", data);
				ClubMgr.getInstance().getHandler().HandleOn_ClubInfo(agent,info);
				break;
			}
			case "hall_dwc_userinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					info.setBasicInfo(shmUser.getUid(), shmUser.getNickName(null),"");
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				//需要的信息，vip等级，rmb1v1的数量，花费的数量，是否注册用户，使用的那个用户头像，
				//核弹头的数量
				JSONObject rev = new JSONObject();
				rev.put("command","hall_dwc_userinfo");
				rev.put("vipLevel", info.getUserVipLevel());
				rev.put("rmb1v1", info.getUserRmb1_1());
				rev.put("huafei", info.getUserHuaFei());
				rev.put("useHeadImg", info.getUseHeadImg());
				rev.put("nuclearNum", info.getUserNuclearNum());
				rev.put("chargenum", info.getUserChargeSum());
				rev.put("isagent", shmUser.getIsAgent());
				rev.put("userRmbType", info.json.optInt("userRmbType"));
				rev.put("useSysZhiFu", info.json.optInt("useSysZhiFu"));
				rev.put("userKeTiXian", info.json.optInt("userKeTiXian"));
				rev.put("dwcAgentLevel", info.json.optInt("agentLevel"));
				rev.put("userKeTiXian", info.json.optInt("userKeTiXian"));
				rev.put("userFreeZuJu", info.json.optInt("userFreeZuJu"));
				rev.put("userPlayCP", info.json.optInt("userPlayCP"));
				rev.put("userPlaySGJ", info.json.optInt("userPlaySGJ"));
				rev.put("sysCanShop", GoldMgr.getInstance().getSysCanShop() ? 1 : 0);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_tx_info":{
				//提现页面总的信息
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				JSONObject statInfo = info.json.optJSONObject("statData");
				if(statInfo != null){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tx_info");
					rev.put("uid", uid);
					rev.put("yongJinSum", statInfo.optDouble("yiTiSum") + statInfo.optDouble("keTiSum"));
					rev.put("yiti", statInfo.optDouble("yiTiSum"));
					rev.put("keti", statInfo.optDouble("keTiSum"));
					rev.put("rmbYjFanLv", DwcRedisRecord.getInstance().getRmbAgentLevelPreset("" + uid));
					agent.SendMessage(rev.toString());
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tx_info");
					rev.put("uid", uid);
					rev.put("yongJinSum",0.0);
					rev.put("yiti", 0.0);
					rev.put("keti", 0.0);
					rev.put("rmbYjFanLv", DwcRedisRecord.getInstance().getRmbAgentLevelPreset("" + uid));
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_tx_record":{
				//提现记录
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}

				JSONObject tiData = info.json.optJSONObject("tiRecordData");
				if(tiData == null){
					JSONObject rev = new JSONObject();
					/*
					tiData = new JSONObject();
					{
						for(int i = 0;i < 7;i++){
							JSONObject newRecord = new JSONObject();
							String key = UserRedisInfo.getRecordTodayKey();
							newRecord.put("time", key);
							newRecord.put("rmb", i * 100.0);
							newRecord.put("danHao",(int)(System.currentTimeMillis() / 1000));
							newRecord.put("account","");
							newRecord.put("status", "ok");
							tiData.put("" + (int)(System.currentTimeMillis() / 1000) + i, newRecord);
						}
						rev.put("tiRecordData",tiData);
					}
					*/
					rev.put("command", "dwc_tx_record");
					agent.SendMessage(rev.toString());
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tx_record");
					rev.put("tiData",tiData);
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_tx_do":{
				//申请提现
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				double erdu = root.optDouble("rmb");
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				boolean ok = info.applyTx(erdu);
				if(ok){
					shmUser.addRmb1v1Value(erdu);
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tx_do");
					rev.put("ok", 1);
					rev.put("rmb", shmUser.getRmb1v1Value());
					agent.SendMessage(rev.toString());
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tx_do");
					rev.put("ok", 0);
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_tg_info":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				boolean isAgent = info.isAgent();
				if(isAgent){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tg_info");
					rev.put("uid", uid);
					int upAgentUid = info.json.optInt("upAgentUid");
					rev.put("agentId", upAgentUid);
					
					JSONObject downAgent = info.getMyDownAgent();
					if(downAgent == null){
						rev.put("tdNum", 0);
						rev.put("userNum", 0);
						rev.put("newNum", 0);
						rev.put("activeNum", 0);
					}else{
//						{
//							downAgent = new JSONObject();
//							//test
//							for(int i  =0;i < 10;i++){
//								int tuid = 1000 + i;
//								JSONObject bindinfo = new JSONObject();
//								bindinfo.put("uid", tuid);
//								bindinfo.put("name", "name" + i);
//								bindinfo.put("time", System.currentTimeMillis() / 1000);
//								downAgent.put("" + tuid,bindinfo);
//							}
//						}
						int tdNum = 0;
						int userNum = 0;
						int newNum = 0;
						int activeNum = 0;

						Iterator iterator = downAgent.keys();
						String todayKey = UserRedisInfo.getRecordTodayKey();
						while(iterator.hasNext()){
							String key = (String) iterator.next();
							JSONObject mem = downAgent.optJSONObject(key);
							if(mem != null){
								userNum++;
								String memdata = DbInfoMgr.getInstance().getUserRedisSaveInfo(mem.optString("uid"));
								
								if(memdata != null){
									UserRedisInfo meminfo = new UserRedisInfo(JSONObject.fromObject(memdata));
									boolean ismemAgent = meminfo.isAgent();
									if(ismemAgent){
										tdNum++;
									}
								}
								Date newdate = new Date(mem.optLong("time") * 1000);
								String newstr = UserRedisInfo.getRecordDayKey(newdate);
								if(newstr.equals(todayKey)){
									newNum++;
								}
								String shareData = DbInfoMgr.getInstance().getUserShareInfo(mem.optString("uid"));
								if(shareData != null){
									UserShareInfo shareInfo = JsonUtils.deserialize(shareData, UserShareInfo.class);
									if(shareInfo.m_loginTime.equals(todayKey)){
										activeNum++;
									}
								}
							}
						}
						rev.put("tdNum", tdNum);
						rev.put("userNum", userNum);
						rev.put("newNum", newNum);
						rev.put("activeNum", activeNum);
					}
					rev.put("tel", info.json.optString("telephone"));
					rev.put("zfbName", info.json.optString("zfbName"));
					rev.put("yinHangName", info.json.optString("yinHangName"));
					rev.put("isAgent", 1);
					rev.put("hasErWeiMa", info.json.optInt("hasErWeiMa"));
					rev.put("userRmbType", info.json.optInt("userRmbType"));
					agent.SendMessage(rev.toString());
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tg_info");
					rev.put("uid", uid);
					int upAgentUid = info.json.optInt("upAgentUid");
					rev.put("agentId", upAgentUid);
					rev.put("tdNum", 0);
					rev.put("userNum", 0);
					rev.put("newNum", 0);
					rev.put("activeNum", 0);
					rev.put("tel", info.json.optString("telephone"));
					rev.put("zfbName", info.json.optString("zfbName"));
					rev.put("yinHangName", info.json.optInt("yinHangName"));
					rev.put("isAgent", 0);
					rev.put("hasErWeiMa", 0);
					rev.put("userRmbType", info.json.optInt("userRmbType"));
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_tg_regagent":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				String tel = root.optString("tel");
				String zfb = root.optString("zfb");
				String yh = root.optString("yh");
				if(!tel.isEmpty()){
					String hasuidcheck = DbInfoMgr.getInstance().getDwcAgentTelCheck(tel);
					if(hasuidcheck != null && !hasuidcheck.equals("" + uid)){
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_tg_regagent");
						rev.put("ok", 0);
						rev.put("reason", "此手机号已被注册过了...");
						agent.SendMessage(rev.toString());
						return true;
					}
				}
				info.setTxInfo(tel, zfb, yh);
				info.setAsAgent();
				//存储下
				DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_tg_regagent");
				rev.put("ok", 1);
				agent.SendMessage(rev.toString());
				return true;
			}
			case "dwc_tg_haserweima":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				info.json.put("hasErWeiMa", 1);
				//存储下
				DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				break;
			}
			case "dwc_tg_activeuser":{
				//是代理才会申请活跃用户
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_tg_activeuser");
				JSONObject list = new JSONObject();
//				if(true){
//					//测试
//					for(int i = 0;i < 12;i++){
//						int tuid = 10050 + i;
//						String name = "name" + i + 100;
//						long tel = 18721592222L + i;
//						long chareSum = 213124 + i * 123;
//						JSONObject activeUser = new JSONObject();
//						activeUser.put("uid", tuid);
//						activeUser.put("regTime", "19/1/19");
//						activeUser.put("name", name);
//						activeUser.put("tel", tel);
//						activeUser.put("charge", chareSum);
//						list.put(activeUser.opt("uid"), activeUser);
//					}
//					rev.put("data", list);
//					agent.SendMessage(rev.toString());
//					return true;
//				}
				JSONObject downAgent = info.getMyDownAgent();

				Iterator iterator = downAgent.keys();
				String todayKey = UserRedisInfo.getRecordTodayKey();
				while(iterator.hasNext()){
					String key = (String) iterator.next();
					JSONObject mem = downAgent.optJSONObject(key);
					if(mem != null){
						
						String shareData = DbInfoMgr.getInstance().getUserShareInfo(mem.optString("uid"));
						if(shareData != null){
							UserShareInfo shareInfo = JsonUtils.deserialize(shareData, UserShareInfo.class);
							if(shareInfo.m_loginTime.equals(todayKey)){
								String memdata = DbInfoMgr.getInstance().getUserRedisSaveInfo(mem.optString("uid"));
								if(memdata != null){
									UserRedisInfo meminfo =  new UserRedisInfo(JSONObject.fromObject(memdata));
									JSONObject activeUser = new JSONObject();
									activeUser.put("uid", meminfo.json.optInt("uid"));
									Date regDate = new Date(meminfo.json.optLong("startTime") * 1000);
									activeUser.put("regTime", UserRedisInfo.getRecordDayKey(regDate));
									activeUser.put("name", meminfo.json.opt("name"));
									activeUser.put("tel", meminfo.json.opt("telephone"));
									activeUser.put("charge", meminfo.json.opt("chargeSum"));
									list.put(activeUser.opt("uid"), activeUser);
								}
							}
						}
					}
				}

				rev.put("data", list);
				agent.SendMessage(rev.toString());
			}
			case "dwc_cy_info":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_cy_info");
				JSONObject list = new JSONObject();
//				if(true){
//				//测试
//					for(int i = 0;i < 12;i++){
//						int tuid = 10050 + i;
//						String name = "name" + i + 100;
//						int gx = 123124 * i * 11;
//						long tel = 18721592222L + i;
//						long chareSum = 213124 + i * 123;
//						JSONObject activeUser = new JSONObject();
//						activeUser.put("uid", tuid);
//						activeUser.put("name", name);
//						activeUser.put("gx", gx);
//						activeUser.put("isAgent", i > 2);
//						activeUser.put("tel", tel);
//						list.put(activeUser.opt("uid"), activeUser);
//					}
//					rev.put("data", list);
//					agent.SendMessage(rev.toString());
//					return true;
//				}
				JSONObject downAgent = info.getMyDownAgent();
				if(downAgent == null){
					rev.put("data", list);
					agent.SendMessage(rev.toString());
					return true;
				}
				Iterator iterator = downAgent.keys();
				String todayKey = UserRedisInfo.getRecordTodayKey();
				String weekKey = "week" + UserRedisInfo.getTodayWeekKey();
				JSONObject userGx = info.json.optJSONObject("yeJiUserGX");
				while(iterator.hasNext()){
					String key = (String) iterator.next();
					JSONObject mem = downAgent.optJSONObject(key);
					if(mem != null){
						JSONObject cyUser = new JSONObject();
						int memuid = mem.optInt("uid");
						String memname = mem.optString("name");						
						String weekUidKey = weekKey + memuid;
						cyUser.put("uid", memuid);
						cyUser.put("name", memname);
						if(userGx != null && userGx.containsKey(weekUidKey)){
							JSONObject usergx = userGx.optJSONObject(weekUidKey);
							cyUser.put("gx", usergx.optDouble("weeksum"));
						}else{
							cyUser.put("gx", 0.0);
						}
						String memdata = DbInfoMgr.getInstance().getUserRedisSaveInfo("" + memuid);
						if(memdata != null){
							UserRedisInfo meminfo =  new UserRedisInfo(JSONObject.fromObject(memdata));
							cyUser.put("isAgent", meminfo.json.optInt("agentLevel") > 0);
							cyUser.put("tel", meminfo.json.optString("telephone"));
						}else{
							cyUser.put("isAgent", false);
							cyUser.put("tel","");
						}
						list.put("" + memuid, cyUser);
					}
				}
				
				rev.put("data", list);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_td_info":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_td_info");
				JSONObject list = new JSONObject();
	//			if(true){
	//			//测试
	//				for(int i = 0;i < 12;i++){
	//					int tuid = 10050 + i;
	//					String name = "name" + i + 100;
	//					int num = 2132 + i;
	//					int gx = 123124 * i * 11;
	//					long tel = 18721592222L + i;
	//					long chareSum = 213124 + i * 123;
	//					JSONObject activeUser = new JSONObject();
	//					activeUser.put("uid", tuid);
	//					activeUser.put("name", name);
	//					activeUser.put("num", num);
	//					activeUser.put("gx", gx);
	//					activeUser.put("tel", tel);
	//					list.put(activeUser.opt("uid"), activeUser);
	//				}
	//				rev.put("data", list);
	//				agent.SendMessage(rev.toString());
	//				return true;
	//			}
				JSONObject downAgent = info.getMyDownAgent();
				if(downAgent == null){
					rev.put("data", list);
					agent.SendMessage(rev.toString());
					return true;
				}
				Iterator iterator = downAgent.keys();
				String todayKey = UserRedisInfo.getRecordTodayKey();
				String weekKey = "week" + UserRedisInfo.getTodayWeekKey();
				JSONObject userGx = info.json.optJSONObject("yeJiUserGX");
				while(iterator.hasNext()){
					String key = (String) iterator.next();
					JSONObject mem = downAgent.optJSONObject(key);
					if(mem != null){
						int memuid = mem.optInt("uid");
						String memdata = DbInfoMgr.getInstance().getUserRedisSaveInfo("" + memuid);
						if(memdata != null){
							UserRedisInfo meminfo =  new UserRedisInfo(JSONObject.fromObject(memdata));
							if(meminfo.json.optInt("agentLevel") > 0){
								//只处理是代理的
								JSONObject tdUser = new JSONObject();
								String memname = mem.optString("name");									
								String weekSumKey = weekKey + "sum";
								tdUser.put("uid", memuid);
								tdUser.put("name", memname);
								JSONObject statData = meminfo.json.optJSONObject("statData");
								if(statData != null && statData.containsKey(weekSumKey)){
									tdUser.put("gx", statData.optDouble(weekSumKey));
								}else{
									tdUser.put("gx",0.0);
								}
								tdUser.put("tel", meminfo.json.opt("telephone"));
								JSONObject downDown = meminfo.getMyDownAgent();
								if(downDown != null){
									tdUser.put("num", downDown.keySet().size());
								}else{
									tdUser.put("num",0);
								}
								list.put("" + memuid, tdUser);
							}
						}
					}
				}
	
				rev.put("data", list);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_down_set_rateinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;

				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				int downuid = root.optInt("downuid");
				int rate = root.optInt("rate");
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_down_set_rateinfo");
				rev.put("uid", downuid);
				JSONObject bindUser = info.json.optJSONObject("bindMeUser");
				if(bindUser == null || bindUser.optJSONObject("" + downuid) == null){
					//不是下级或者找不到
					rev.put("success", 0);
					rev.put("reason", "此用户不是您的下级代理");
					agent.SendMessage(rev.toString());
					return false;
				}
				int myrate = DwcRedisRecord.getInstance().getRmbAgentLevelPreset("" + uid);
				if(myrate == 0 || rate >= myrate){
					rev.put("success", 0);
					rev.put("reason", "您只能设置比您自己更低的赔率");
					agent.SendMessage(rev.toString());
					return false;
				}
				DwcRedisRecord.getInstance().setRmbAgentLevelPreSet("" + downuid, rate);
				rev.put("success", 1);
				rev.put("uid", downuid);
				rev.put("fanlv", rate);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_down_agent_rateinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_down_agent_rateinfo");
				List<String> infos = new ArrayList<String>();
//				if(true){
//				//测试
//					for(int i = 0;i < 12;i++){
//						int tuid = 10050 + i;
//						String name = "name" + i + 100;
//						JSONObject activeUser = new JSONObject();
//						activeUser.put("uid", tuid);
//						activeUser.put("name", name);
//						activeUser.put("fanlv", 290);
//						infos.add(activeUser.toString());
//					}
//					rev.put("data", infos);
//					agent.SendMessage(rev.toString());
//					return true;
//				}
				JSONObject downAgent = info.getMyDownAgent();
				if(downAgent == null){
					rev.put("data", infos);
					agent.SendMessage(rev.toString());
					return true;
				}
				Iterator iterator = downAgent.keys();
				while(iterator.hasNext()){
					String key = (String) iterator.next();
					JSONObject mem = downAgent.optJSONObject(key);
					if(mem != null){
						int memuid = mem.optInt("uid");
						String name = mem.optString("name");
						int rate = DwcRedisRecord.getInstance().getRmbAgentLevelPreset("" + memuid);
						JSONObject activeUser = new JSONObject();
						activeUser.put("uid", memuid);
						activeUser.put("name", name);
						activeUser.put("fanlv", rate);
						infos.add(activeUser.toString());
					}
				}
	
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_jl_info":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_jl_info");
				JSONObject list = new JSONObject();
				List<String> infos = DwcRedisRecord.getInstance().getRmbAgentJiangLi("" + uid,100);
				for(int i = 0;i < infos.size();i++){
					list.put("" + i, infos.get(i));
				}
//				if(infos.size() == 0){
//					//测试
//					for(int i = 0;i < 500;i++){
//						String weekTime = "time" + i * 2;
//						JSONObject weekjlJson = new JSONObject();
//						weekjlJson.put("time", weekTime);
//						weekjlJson.put("geren",1000 + i * 100);
//						weekjlJson.put("td", 500 + i * 100);
//						weekjlJson.put("sum",400 + i * 100);
//						weekjlJson.put("rmb", 10 + i * 0.03);
//						list.put("" + i, weekjlJson);
//					}
//				}
				rev.put("data", list);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_yj_info":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_yj_info");
				info.getCurrWeekInfo(rev);
				JSONObject list = new JSONObject();
				List<String> infos = DwcRedisRecord.getInstance().getRmbAgentYejiRecord("" + uid,100);
				for(int i = 0;i < infos.size();i++){
					list.put("" + i, infos.get(i));
				}
//				if(infos.size() == 0){
//					//测试
//					for(int i = 0;i < 500;i++){
//						String weekTime = "19/19";
//						JSONObject weekjlJson = new JSONObject();
//						weekjlJson.put("time", weekTime);
//						weekjlJson.put("geren",1000 + i * 100);
//						weekjlJson.put("td", 500 + i * 100);
//						weekjlJson.put("sum",400 + i * 100);
//						list.put("" + i, weekjlJson);
//					}
//				}
				rev.put("data", list);
				agent.SendMessage(rev.toString());
				break;
			}
			
			case "dwc_tg_bindagent":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int agentid = root.optInt("id");
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(agentid));
				UserRedisInfo info = null;
				if(data == null){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tg_bindagent");
					rev.put("ok", 0);
					rev.put("reason", "找不到代理帐号");
					agent.SendMessage(rev.toString());
					break;
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info.json.optInt("userRmbType") == 1){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tg_bindagent");
					rev.put("ok", 0);
					rev.put("reason", "此代理为租赁用户,您无法绑定");
					agent.SendMessage(rev.toString());
					break;
				}
				if(info.json.optInt("agentLevel") < 0){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_tg_bindagent");
					rev.put("ok", 0);
					rev.put("reason", "此id用户不是代理...");
					agent.SendMessage(rev.toString());
					break;
				}
				data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo newinfo =  new UserRedisInfo(JSONObject.fromObject(data));
				newinfo.setUpAgentUid(agentid);
				newinfo.json.put("userRmbType", info.json.optInt("userRmbType"));
				DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid, newinfo.getUserInfoStr());
				info.bindDownUser(info.json.optInt("upAgentUid") == 1000?1:info.json.optInt("agentLevel") + 1, uid, newinfo.json.optString("name"));
				DbInfoMgr.getInstance().setUserRedisSaveInfo("" + agentid, info.getUserInfoStr());
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_tg_bindagent");
				rev.put("ok", 1);
				rev.put("agentId", agentid);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_user_rank":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String type = root.optString("type");
				if(type.equals("jushu")){
					List<String> data = DwcRedisRecord.getInstance().getTodayJuShuTop50();
//					if(data.size() == 0){
//						for(int i = 0;i < 100;i++){
//							DwcRankDef def = new DwcRankDef();
//							def.uid = 1000 + i;
//							def.name = "name1" + i + 2;
//							def.m_headUrl = DbInfoMgr.getInstance().getUserAvatarUrl(uid);
//							def.m_rank = i + 1;
//							def.dwcJuShu = 100 +i;
//							data.add(JsonUtils.serialize(def));
//						}
//					}
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_user_rank");
					rev.put("type", type);
					rev.put("data", data);
					agent.SendMessage(rev.toString());
				}else if(type.equals("won")){
					List<String> data = DwcRedisRecord.getInstance().getTodayWonMoneyTop50();
//					if(data.size() == 0){
//						for(int i = 0;i < 100;i++){
//							DwcRankDef def = new DwcRankDef();
//							def.uid = 1000 + i;
//							def.name = "name1" + i + 2;
//							def.m_headUrl = DbInfoMgr.getInstance().getUserAvatarUrl(uid);
//							def.m_rank = i + 1;
//							def.wonMoney = 100 +i;
//							data.add(JsonUtils.serialize(def));
//						}
//					}
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_user_rank");
					rev.put("type", type);
					rev.put("data", data);
					agent.SendMessage(rev.toString());
				}else if(type.equals("wonrate")){
					List<String> data = DwcRedisRecord.getInstance().getTodayWonRateTop50();
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_user_rank");
					rev.put("type", type);
					rev.put("data", data);
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_user_setting":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_user_setting");
				rev.put("tel", info.json.opt("telephone"));
				rev.put("isAgent", info.json.optInt("agentLevel") > 0);
				rev.put("headurl", info.json.optInt("headUrl"));
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_user_tx_record":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				List<String> data = DwcRedisRecord.getInstance().getDwcUserTxRecord(uid);
//				if(data.size() == 0){
//					for(int i = 0;i < 100;i++){
//						JSONObject json = new JSONObject();
//						json.put("uid", uid);
//						json.put("name", "aa");
//						json.put("time", UserRedisInfo.getRecordTodayKey());
//						json.put("accountName", "zhwsh00@126.com");
//						json.put("danhao", (int)(System.currentTimeMillis() / 1000));
//						json.put("type", "银行卡帐号");
//						json.put("erdu", 1000 + 11*i);
//						data.add(json.toString());
//					}
//				}
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_user_tx_record");
				rev.put("data", data);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_pifa_cha":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int userid = root.optInt("id");
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_pifa_cha");
					rev.put("success", 0);
					rev.put("reason", "您不是代理!");
					agent.SendMessage(rev.toString());
					break;
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info.isDownUser(userid)){
					JSONObject down = info.getBindDownUserInfo(userid);
					if(down == null){
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_pifa_cha");
						rev.put("success", 0);
						rev.put("reason", "找不到此用户信息，请检查后继续");
						agent.SendMessage(rev.toString());
					}else{
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_pifa_cha");
						rev.put("success", 1);
						rev.put("name", down.opt("name"));
						agent.SendMessage(rev.toString());
					}
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_pifa_cha");
					rev.put("success", 0);
					rev.put("reason", "此用户不是您的下级绑定玩家!");
					agent.SendMessage(rev.toString());
					break;
				}
				break;
			}
			case "dwc_pifa_do":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				int userid = root.optInt("id");
				int clubid = root.optInt("clubid");
				int fund = root.optInt("fund");
				if(userid <= 0 || fund <= 0){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_pifa_do");
					rev.put("success", 0);
					rev.put("reason", "批发信息不对,请仔细检查!");
					agent.SendMessage(rev.toString());
					break;
				}
				boolean caninclub = false;
				if(clubid != 0 && (ClubRedis.isClubAdmin(clubid,uid) || ClubRedis.isClubOwner(clubid, uid))){
					caninclub = true;
				}
				if(caninclub || info.isDownUser(userid)){
					data = DbInfoMgr.getInstance().getUserRedisSaveInfo("" + userid);
					if(data == null){
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_pifa_do");
						rev.put("success", 0);
						rev.put("reason", "找不到此用户信息,请检查后继续!");
						agent.SendMessage(rev.toString());
						break;
					}else{
						if(info.json.optDouble("Rmb1_1") < fund){
							JSONObject rev = new JSONObject();
							rev.put("command", "dwc_pifa_do");
							rev.put("success", 0);
							rev.put("reason", "您的当前资金不足,请检查后继续!");
							agent.SendMessage(rev.toString());
							break;
						}
						UserRedisInfo agentInfo = new UserRedisInfo(JSONObject.fromObject(data));
						info.addUserRmb1_1(-fund);
						agentInfo.addUserRmb1_1(fund);
						//添加用户充值信息
						agentInfo.addUserCharge(fund);
						info.addUserTiXianRmb1v1(fund);
						DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid,info.getUserInfoStr());
						DbInfoMgr.getInstance().setUserRedisSaveInfo("" + userid,agentInfo.getUserInfoStr());
						//真金变化记录
						//public static void handleRmbChange(int uid,double change,double before,double after,String reason){
						UserRmbChange.handleRmbChange(uid, -fund, info.json.optDouble("Rmb1_1") + fund,info.json.optDouble("Rmb1_1"),UserRmbChange.reason104);
						UserRmbChange.handleRmbChange(userid, fund, agentInfo.json.optDouble("Rmb1_1") - fund,agentInfo.json.optDouble("Rmb1_1"),UserRmbChange.reason105);
						//记录给代理
						DwcRedisRecord.getInstance().addAgentPiFaRecord(uid,userid,agentInfo.json.optString("name"),fund);
						//发布消息给用户
						net.sf.json.JSONObject pub = new net.sf.json.JSONObject();
						pub.put("command","public_dwc_agent_pifa");
						pub.put("value1",userid);
						pub.put("value2",fund);
						AdminRedis.getInstance().pubAdminSubMsg(pub);
						//返回
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_pifa_do");
						rev.put("success", 1);
						rev.put("rmb", info.json.opt("Rmb1_1"));
						agent.SendMessage(rev.toString());
					}
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_pifa_do");
					rev.put("success", 0);
					rev.put("reason", "此用户不是您的下级绑定玩家!");
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_zhuan_do":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				int userid = root.optInt("id");
				int clubid = root.optInt("clubid");
				double fund = root.optDouble("fund");
				if(userid <= 0 || fund <= 0){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_zhuan_do");
					rev.put("success", 0);
					rev.put("reason", "转出信息不对,请仔细检查!");
					agent.SendMessage(rev.toString());
					break;
				}

				boolean caninclub = false;
				if(clubid != 0 && (ClubRedis.isClubAdmin(clubid,userid) || ClubRedis.isClubOwner(clubid, userid))){
					caninclub = true;
				}
				if(caninclub || info.json.optInt("upAgentUid") == userid){
					data = DbInfoMgr.getInstance().getUserRedisSaveInfo("" + userid);
					if(data == null){
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_zhuan_do");
						rev.put("success", 0);
						rev.put("reason", "找不到您的代理信息,请检查后继续!");
						agent.SendMessage(rev.toString());
						break;
					}else{
						if(info.json.optDouble("Rmb1_1") < fund){
							JSONObject rev = new JSONObject();
							rev.put("command", "dwc_zhuan_do");
							rev.put("success", 0);
							rev.put("reason", "您的当前资金不足,请检查后继续!");
							agent.SendMessage(rev.toString());
							break;
						}
						UserRedisInfo agentInfo = new UserRedisInfo(JSONObject.fromObject(data));
						info.addUserRmb1_1(-fund);
						agentInfo.addUserRmb1_1(fund);
						//添加平衡控制
						agentInfo.addUserCharge(fund);
						info.addUserTiXianRmb1v1(fund);
						
						DbInfoMgr.getInstance().setUserRedisSaveInfo("" + uid,info.getUserInfoStr());
						DbInfoMgr.getInstance().setUserRedisSaveInfo("" + userid,agentInfo.getUserInfoStr());
						//真金变化记录
						UserRmbChange.handleRmbChange(uid, -fund, info.json.optDouble("Rmb1_1") + fund,info.json.optDouble("Rmb1_1"),UserRmbChange.reason106);
						UserRmbChange.handleRmbChange(userid, fund, agentInfo.json.optDouble("Rmb1_1") - fund,agentInfo.json.optDouble("Rmb1_1"),UserRmbChange.reason107);
						//记录给代理
						DwcRedisRecord.getInstance().addUserZhuanRecord(uid,userid,agentInfo.json.optString("name"),fund);
						//发布消息给用户
						net.sf.json.JSONObject pub = new net.sf.json.JSONObject();
						pub.put("command","public_dwc_user_zhuan");
						pub.put("value1",userid);
						pub.put("value2",fund);
						AdminRedis.getInstance().pubAdminSubMsg(pub);
						//返回
						JSONObject rev = new JSONObject();
						rev.put("command", "dwc_zhuan_do");
						rev.put("success", 1);
						rev.put("rmb", info.json.opt("Rmb1_1"));
						agent.SendMessage(rev.toString());
					}
				}else{
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_zhuan_do");
					rev.put("success", 0);
					rev.put("reason", "此用户不是您的上级代理!");
					agent.SendMessage(rev.toString());
				}
				break;
			}
			case "dwc_agent_pifa_record":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_agent_pifa_record");
				List<String> infos = DwcRedisRecord.getInstance().getAgentPiFaRecord("" + uid);
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_user_zhuan_record":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_agent_pifa_record");
				List<String> infos = DwcRedisRecord.getInstance().getUserZhuanRecord("" + uid);
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_rent_user_weekinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_rent_user_weekinfo");
				List<String> infos = DwcRedisRecord.getInstance().getRentUserWeekInfo("" + uid);
//				if(infos.size() == 0){
//					//test
//					for(int i = 0;i < 10;i++){
//						JSONObject json = new JSONObject();
//						String weekkey = UserRedisInfo.getRecordWeekStartEndKey();
//						json.put("time", weekkey);
//						json.put("td", i * 10);
//						json.put("gr", 0);
//						json.put("sum", i * 10);
//						infos.add(json.toString());
//					}
//				}
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_rent_user_tdinfo":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info == null)
					break;
				String week = root.optString("week");
				List<String> uids = new ArrayList<String>();
				JSONObject binduser = info.json.optJSONObject("bindMeUser");
				if(binduser != null){
					Iterator iterator = binduser.keys();
					while(iterator.hasNext()){
						String key = (String) iterator.next();
						JSONObject mem = binduser.optJSONObject(key);
						UserRedisInfo memInfo = new UserRedisInfo(JSONObject.fromObject(DbInfoMgr.getInstance().getUserRedisSaveInfo("" + mem.optInt("uid"))));
						if(memInfo.json.optInt("agentLevel") > 0)
							uids.add("" + mem.optInt("uid"));
					}
				}
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_rent_user_tdinfo");
				List<String> infos = DwcRedisRecord.getInstance().getRentUserWeekTdInfo(week,uids);
//				if(infos.size() == 0){
//					//test
//					for(int i = 0;i < 10;i++){
//						JSONObject json = new JSONObject();
//						String weekkey = UserRedisInfo.getRecordWeekStartEndKey();
//						json.put("time", weekkey);
//						json.put("td", i * 10);
//						json.put("gr", 0);
//						json.put("sum", i * 10);
//						json.put("name", "name" + i);
//						json.put("id", 100 + i);
//						json.put("tel", 1111234562 + i);
//						infos.add(json.toString());
//					}
//				}
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}

			case "club_zhanji":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int clubid = root.optInt("clubid");
				int currnum = root.optInt("num");
				int index = root.optInt("index");
				JSONObject rev = new JSONObject();
				rev.put("command", "club_zhanji");
				List<String> infos = DwcRedisRecord.getInstance().getZhanJiByClubIndex(clubid,currnum,index);
				rev.put("data", infos);
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_can_pifa":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int pifaid = root.optInt("id");
				int clubid = root.optInt("clubid");
				//在俱乐部内管理可以跟任何人上分
				if(clubid != 0 && (ClubRedis.isClubAdmin(clubid,uid) || ClubRedis.isClubOwner(clubid, uid))){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_can_pifa");
					rev.put("id", pifaid);
					rev.put("clubid", clubid);
					agent.SendMessage(rev.toString());
					break;
				}
				//判断是不是我的绑定用户
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info == null)
					break;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_can_pifa");
				rev.put("id", pifaid);
				rev.put("clubid", 0);
				JSONObject bindMeUser = info.json.optJSONObject("bindMeUser");
				if(bindMeUser != null && bindMeUser.containsKey("" + pifaid)){
					rev.put("success", 1);
				}else{
					rev.put("success", 0);
					rev.put("reason", "无绑定关系");
				}
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_can_zhuan":{
				int uid = agent.getUid();
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				int zhuanid = root.optInt("id");
				int clubid = root.optInt("clubid");
				//在俱乐部内管理可以跟任何人上分
				if(clubid != 0 && (ClubRedis.isClubAdmin(clubid,zhuanid) || ClubRedis.isClubOwner(clubid, zhuanid))){
					JSONObject rev = new JSONObject();
					rev.put("command", "dwc_can_zhuan");
					rev.put("id", zhuanid);
					rev.put("clubid", clubid);
					agent.SendMessage(rev.toString());
					break;
				}
				//判断是不是我的上级
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info == null)
					break;
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_can_zhuan");
				rev.put("id", zhuanid);
				rev.put("clubid", 0);
				int agentId = info.json.optInt("upAgentUid");
				if(agentId == zhuanid){
					rev.put("success", 1);
					rev.put("id", zhuanid);
				}else{
					rev.put("success", 0);
					rev.put("reason", "无绑定关系");
				}
				agent.SendMessage(rev.toString());
				break;
			}
			case "dwc_changenick":{
				int uid = agent.getUid();
				String newname = root.optString("name");
				SHMUser shmUser = dthall.getInstance().getUserInfo(uid);
				if(shmUser == null)
					return false;
				String data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(uid));
				UserRedisInfo info = null;
				if(data == null){
					info = new UserRedisInfo();
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(uid),info.getUserInfoStr());
				}else{
					info =  new UserRedisInfo(JSONObject.fromObject(data));
				}
				if(info == null)
					break;
				info.json.put("name",newname);
				int upId = info.json.optInt("upAgentUid");
				if(upId != 0 && upId != 1000){
					//存在上级
					data = DbInfoMgr.getInstance().getUserRedisSaveInfo(String.valueOf(upId));
					UserRedisInfo upinfo =  new UserRedisInfo(JSONObject.fromObject(data));
					JSONObject bindMe = upinfo.json.optJSONObject("bindMeUser");
					bindMe.optJSONObject("" + uid).put("name", newname);
					upinfo.json.put("bindMeUser",bindMe);
					DbInfoMgr.getInstance().setUserRedisSaveInfo(String.valueOf(upId),upinfo.getUserInfoStr());
				}
				shmUser.setNickName(newname);
				ClubRedis.getInstance().changeUserClubName(uid, newname);
				//改变mysql的
				DbInfoMgr.getInstance().changeNickName(uid,newname);
				JSONObject rev = new JSONObject();
				rev.put("command", "dwc_changenick");
				rev.put("name", newname);
				agent.SendMessage(rev.toString());
				break;
			}
		}
		return true;
	}
}
